<?php 
class CategoryControl extends CommonControl{

    /**
     * 添加商品列表页
     * @return [type] [description]
     */
    public function index(){
        $db=M('g_category');
        $total = $db->count();
        // 分页
        // $page = new page($total);
        $data = $db->all();  
        // $this->assign("page", $page->show());
        $data = Data::channelList($data,0,"──");
        $this->assign('field',$data);
        $this->display();  
    }

    /**
     * 添加商品栏目
     */
    public function add(){
        if(IS_POST){
            $db=M('g_category')->add();
            $this->success('添加栏目成功','index',1);
        }else{
            $db=M('g_goods_type')->all();
            $this->assign('field',$db);
             //栏目等级
            $data=array(
                "level"=>0,
                "pid"=>0
            );
            if($cid= q("get.cid","intval")){
                $pCat=$db->table("category")->find("cid=$cid");
                $data['level']=$pCat['level']+1;
                $data['pid']=$pCat['cid'];
            }
            $this->assign("data",$data);
            $this->display();  
        }
        
    }
    /**
     * 删除商品栏目
     * @return [type] [description]
     */
    public function del(){
        $cid = $_GET['cid'];
        $db = M('g_category')->where("cid=".$cid)->del();
        $this->success('删除成功','index',1);
    }




}
?>